package com.icez.base_util_library.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment

/**
 * fragment基类
 * @sample
 * @author Icez
 */
abstract class BaseFragment<B:ViewDataBinding>:Fragment(),View.OnClickListener {
    // binding类
    var mBinding:B? = null
    // 根布局
    private var mRoot:View? = null

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        if(mRoot==null){
            mBinding = DataBindingUtil.inflate(inflater,getContentView(),container,false)
            mBinding?.lifecycleOwner = this
            getBundleParams()
            initClick()
            initViewValue()
            mRoot = mBinding?.root
        }
        return mRoot
    }

    /**
     * 获取内容布局
     * @sample
     * @author Icez
     */
    abstract fun getContentView():Int

    /**
     * 获取传递过来的参数
     * @sample
     * @author Icez
     */
    abstract fun getBundleParams()

    /**
     * 初始化点击事件
     * @sample
     * @author Icez
     */
    abstract fun initClick()

    /**
     * 初始init
     * @sample
     * @author Icez
     */
    abstract fun initViewValue()



}